package com.aidex.biz.service.impl;

import com.aidex.biz.domain.CapBill;
import com.aidex.biz.domain.Customer;
import com.aidex.biz.domain.ZifangPush;
import com.aidex.biz.mapper.CapBillMapper;
import com.aidex.biz.service.CapBillService;
import com.aidex.biz.service.ZiFangService;
import com.aidex.biz.service.ZifangPushService;
import com.aidex.biz.utils.hengchang.HengChangServer;
import com.aidex.biz.utils.hengchang.HengChangServerImpl;
import com.aidex.common.annotation.DataScope;
import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.common.utils.NumberUtils;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 资方Service业务层处理
 * @author sean
 * @email 2074844820@qq.com
 * @date 2023-12-17
 */
@Service
@Transactional(readOnly = true)
public class ZiFangServiceImpl implements ZiFangService
{
    private static final Logger log = LoggerFactory.getLogger(ZiFangServiceImpl.class);

    @Autowired
    private HengChangServer hengChangServer;

    @Autowired
    private ZifangPushService zifangPushService;
    @Override
    public JSONObject pushHengChang(Customer customer) {
        JSONObject jsonObject=new JSONObject();
        // 先进行撞库
        jsonObject=hengChangServer.synCustomerInfoPreApprovalRushData(customer);
        ZifangPush zifangPush=new ZifangPush();
        zifangPush.setCusName(customer.getCusName());
        zifangPush.setCusPhone(customer.getPhone());
        zifangPush.setCustomerId(customer.getId());
        zifangPush.setQudaoType("恒昌");
        if(jsonObject.getIntValue("code")==200){
            jsonObject=hengChangServer.synChannelCustomerInfo(customer);
            if(200==jsonObject.getIntValue("code")){
                zifangPush.setId(jsonObject.getString("channelOrderNum"));
                zifangPush.setIsNewRecord();;
                if(200==jsonObject.getJSONObject("data").getIntValue("code")){
                    // 撞库成功后进行推送
                    zifangPush.setStatus("0");
                    zifangPush.setRemark("恒昌-推送成功！");
                }else{
                    zifangPush.setStatus("1");
                    zifangPush.setRemark(jsonObject.getJSONObject("data").getString("msg"));
                }
            }
        }else{
            zifangPush.setStatus("1");
            zifangPush.setRemark("客户信息撞库");
        }
        zifangPushService.save(zifangPush);
        return jsonObject;
    }
}
